import Base from "./Base";
import utils from "src/utils";
import { Props } from "src/types/shape";
import { shapeType } from "src/types/drawBoard";

export interface PentagramProps {
  x: number;
  y: number;
  radius: number;
  borderWidth?: number;
  borderColor?: string;
  bgcolor?: string;
}

export default class extends Base {
  constructor(option: PentagramProps) {
    super(shapeType.pentagram)
    utils.object.Assign(option, this.props)
    this.props.width = option.radius * 2
    this.props.height = option.radius * 2
  }
  draw(ctx: CanvasRenderingContext2D, osCtx: OffscreenCanvasRenderingContext2D): void {
    const { x, y, radius } = this.props


    ctx.save()

    this.transform(ctx)
    ctx.beginPath()
    this.initOptions(ctx, 1)

    // ctx.moveTo(x, y);
    // ctx.translate(400,400)
    let _x, _y
    for (let i = 0; i < 5; i++) {
      _x = Math.cos((18 + 72 * i) / 180 * Math.PI) * radius
      _y = -Math.sin((18 + 72 * i) / 180 * Math.PI) * radius
      ctx.lineTo(_x + x + radius, _y + y + radius)
      _x = Math.cos((54 + 72 * i) / 180 * Math.PI) * radius / 2
      _y = -Math.sin((54 + 72 * i) / 180 * Math.PI) * radius / 2
      ctx.lineTo(_x + x + radius, _y + y + radius)
    }

    ctx.closePath()
    ctx.stroke()

    ctx.restore()

    // 镜像画布
    this.drawMirror(osCtx)
  }
  setProps(option: Props): void {
    super.setProps(option)
    this.props.width = option.radius * 2
    this.props.height = option.radius * 2
  }
}